package com.sgb.capital.view.ui.adapter;

import com.sgb.capital.R;
import com.sgb.capital.model.CommodityBean;
import com.sgb.capital.utils.Utils;
import com.sgb.capital.view.widget.BaseRecyclerViewAdapterHelper.BaseQuickAdapter;
import com.sgb.capital.view.widget.BaseRecyclerViewAdapterHelper.viewholder.BaseViewHolder;

import java.util.List;

/**
 * 作者:张磊
 * 日期:2021/11/17 0016
 * 说明:询价或报价
 */
public class CommodityListAdapter extends BaseQuickAdapter<CommodityBean.ListDTO, BaseViewHolder> {

    public String mType = "报价";
    public int mPos;

    public CommodityListAdapter(List<CommodityBean.ListDTO> beans) {
        super(R.layout.commoditylist_adapter, beans);
    }

    @Override
    protected void convert(BaseViewHolder helper, final CommodityBean.ListDTO item) {



        // 报价时间：2020-03-13
        String str = ((mType.contains("询价") && mPos == 1) ? "发布时间：" : "报价时间：") +
                (mType.contains("报价") ? Utils.get2Time(item.quoteTime) :
                        mPos == 0 ? item.quoteTime == 0 ? "/" : Utils.get2Time(item.quoteTime) :
                                item.updateTime == 0 ? "/" : Utils.get2Time(item.updateTime));
        String info = item.catAndAttrs.replace(" ", "/");
        boolean isShow = info.contains(",");
        helper
                .setText(R.id.tv_name, item.publishUserName)
                .setText(R.id.tv1info, isShow ? info.split(",")[0] : info)
                .setText(R.id.tv_quote_time, Utils.getKeyWordSpan(Utils.getColor(R.color.color_666666), str, (mType.contains("询价") && mPos == 1) ? "发布时间：" :
                        "报价时间："))
                .setText(R.id.tv_end_time, "报价截止：" + Utils.get2Time(item.deadlineTime))
                .setText(R.id.tv2info, isShow ? info.split(",")[1] : "")
                .setGone(R.id.tv2info, !isShow)
                .setImageResource(R.id.iv_image, item.status.equals("1") ? R.mipmap.quote_wait_icon : R.mipmap.quote_icon)
        ;
    }
}